home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / positi.000 / module1.bas < prev    next >
BASIC Source File  |  1995-12-22  |  3KB  |  67 lines

  1. ' this is a small example that show you how to
  2. ' save form positions and restore then. I hope you
  3. ' like this and if you have any new idea please
  4. ' write me at NOlazabal@AOL.com or Nolazabal@MSN.com
  5.  
  6. 'API Declarations
  7. Declare Function GetPrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
  8. Declare Function WritePrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lplFileName As String) As Integer
  9.  
  10. 'Variable Declarations
  11. Global r%       'Result Code from WritePrivateProfileString
  12. Global inipath$ 'Path to .ini file
  13. Global Lft$, Top$, hei$, wid$
  14. Global glft
  15.  
  16.     Sub centerme (frm As Form)
  17.         Dim x, y        'New directions for the form
  18.         x = (Screen.Width - frm.Width) / 2
  19.         y = (Screen.Height - frm.Height) / 2
  20.         frm.Move x, y       'Change the location of the form
  21.     End Sub
  22.  
  23. Sub Get_Position (frm As Form, formname$)
  24.     Dim glft, gtop, ghei, gwid
  25.     inipath$ = app.Path + "\positi.ini"
  26.     glft = GetFromINI(formname$, "Left", inipath$)
  27.     gtop = GetFromINI(formname$, "Top", inipath$)
  28.     ghei = GetFromINI(formname$, "Height", inipath$)
  29.     gwid = GetFromINI(formname$, "Width", inipath$)
  30.     If glft <> "" Then
  31.      frm.Left = glft
  32.     End If
  33.     If gtop <> "" Then
  34.      frm.Top = gtop
  35.     End If
  36.     If ghei <> "" Then
  37.      frm.Height = ghei
  38.     End If
  39.     If gwid <> "" Then
  40.      frm.Width = gwid
  41.     End If
  42. End Sub
  43.  
  44. Function GetFromINI (AppName$, KeyName$, FileName$) As String
  45.    Dim RetStr As String
  46.    RetStr = String(255, Chr(0))
  47.    GetFromINI = Left(RetStr, GetPrivateProfileString(AppName$, ByVal KeyName$, "", RetStr, Len(RetStr), FileName$))
  48.    form1.Print getgrimini
  49. End Function
  50.  
  51. Sub Save_Position (frm As Form, formname$)
  52.     inipath$ = app.Path + "\positi.ini"
  53.     Lft$ = frm.Left
  54.     Top$ = frm.Top
  55.     hei$ = frm.Height
  56.     wid$ = frm.Width
  57.     r% = WritePrivateProfileString(formname$, "Left", Lft$, inipath$)
  58.     If r% <> 1 Then MsgBox "An error occurred while writing Left."
  59.     r% = WritePrivateProfileString(formname$, "Top", Top$, inipath$)
  60.     If r% <> 1 Then MsgBox "An error occurred while writing Top."
  61.     r% = WritePrivateProfileString(formname$, "Height", hei$, inipath$)
  62.     If r% <> 1 Then MsgBox "An error occurred while writing Height."
  63.     r% = WritePrivateProfileString(formname$, "Width", wid$, inipath$)
  64.     If r% <> 1 Then MsgBox "An error occurred while writing Width."
  65. End Sub
  66.  
  67.